import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/settings_controller.dart';
import '../l10n/app_localizations.dart';

class SettingsMenu extends StatelessWidget {
  const SettingsMenu({super.key});

  @override
  Widget build(BuildContext context) {
    final SettingsController controller = Get.find();
    final l10n = AppLocalizations.of(context);

    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            const Color(0xFF0084FF).withOpacity(0.4),
            const Color(0xFF0084FF),
          ],
        ),
        borderRadius: BorderRadius.circular(12.r),
        border: Border.all(color: const Color(0xFF05FFFD), width: 1.5.r),
      ),
      child: Obx(
        () => Column(
          children:
              controller.menuItems.map((item) {
                return _buildMenuItem(item, l10n, controller);
              }).toList(),
        ),
      ),
    );
  }

  Widget _buildMenuItem(
    Map<String, dynamic> item,
    AppLocalizations l10n,
    SettingsController controller,
  ) {
    final String title = _getLocalizedTitle(item['id'], l10n);

    return GestureDetector(
      onTap: () => controller.handleMenuItemTap(item['id']),
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: const Color(0xFF00FFFF).withOpacity(0.2),
              width: 0.5,
            ),
          ),
        ),
        child: Row(
          children: [
            // 图标
            Icon(item['icon'] as IconData, color: Colors.white, size: 32.sp),

            SizedBox(width: 16.w),

            // 标题
            Expanded(
              child: Text(
                title,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),

            // 箭头
            Icon(Icons.arrow_forward_ios, color: Colors.white, size: 18.sp),
          ],
        ),
      ),
    );
  }

  String _getLocalizedTitle(String itemId, AppLocalizations l10n) {
    switch (itemId) {
      case 'physical_machine':
        return l10n.physicalMachineRoom;
      case 'vip_upgrade':
        return l10n.vipUpgradeMenu;
      case 'faq':
        return l10n.frequentlyAskedQuestions;
      case 'rating':
        return l10n.rating;
      case 'comment':
        return l10n.comment;
      case 'customer_service':
        return l10n.customerService;
      case 'privacy':
        return l10n.privacyWebsite;
      case 'terms':
        return l10n.termsOfService;
      default:
        return itemId;
    }
  }
}
